﻿using UnityEngine;
using System.Collections;

public class GameObjectHelper
{
  public static T Find<T>(Transform check, string name, bool deep) where T : Component
  {
    foreach (T t in check.GetComponentsInChildren<T>())
    {
      if (t.name == name) { return t; }
    }

    if (deep)
    {
      foreach (T t in check.GetComponentsInChildren<T>())
      {
        if (t.gameObject != check.gameObject)
        {
          T sub_t = Find<T>(t.transform, name, deep);
          if (sub_t != null)
            return sub_t;
        }
      }
    }
    
    return null;
  }
}
